//
//  RecomViewController.m
//  Korea
//
//  Created by 崔剑 on 15/8/24.
//  Copyright (c) 2015年 KoreaGo. All rights reserved.
//

#import "RecomViewController.h"
#import "HMSegmentedControl.h"
#import "UIColor+RGBColor.h"
#import "BestHotViewController.h"
#import "BestNewViewController.h"
#import "Header.h"
#import "LoginViewController.h"
@interface RecomViewController ()<UIScrollViewDelegate>
@property (nonatomic, strong) HMSegmentedControl *segment;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) NSMutableArray *dataArray;
@end

@implementation RecomViewController

- (NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [NSMutableArray arrayWithObjects:@"每日最新", @"in韩国", nil];
    }
    return _dataArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"韩流前线";
    self.navigationController.navigationBar.translucent = NO;
    [self creatView];
    
    
}

-(void)creatView{
    [self.view addSubview:self.segment];
    [self.view addSubview:self.scrollView];
    [self.segment addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    
    BestNewViewController *new = [[BestNewViewController alloc] init];
    new.view.frame = CGRectMake(0, 0, self.view.width, self.view.height);
    [self addChildViewController:new];
    [self.scrollView addSubview:new.view];
    
    BestHotViewController *hot = [[BestHotViewController alloc] init];
    hot.view.frame = CGRectMake(self .view.width, 0, self.view.width, self.view.height);
    [self addChildViewController:hot];
    [self.scrollView addSubview:hot.view];
    
    
    
    
}

#pragma mark 创建分栏视图控制器
- (HMSegmentedControl *)segment{
    if (!_segment) {
        _segment = [[HMSegmentedControl alloc] initWithSectionTitles:self.dataArray];
        _segment.frame = CGRectMake(0, 0, self.view.width, 36);
        _segment.selectionIndicatorHeight = 2.5f;
        _segment.selectionIndicatorColor = [UIColor colorWithRGB:0xfe868f alpha:1];
        _segment.selectionIndicatorLocation = 1;
        _segment.selectionStyle = HMSegmentedControlSelectionStyleFullWidthStripe;
        _segment.selectedTitleTextAttributes = @{NSForegroundColorAttributeName : [UIColor colorWithRGB:0xfe868f alpha:1]}; 
        _segment.verticalDividerEnabled = YES;
        _segment.verticalDividerColor = [UIColor colorWithRGB:0xfe868f alpha:1];
        _segment.titleTextAttributes = @{NSFontAttributeName : [UIFont fontWithName:@"Helvetica" size:16]};
        _segment.verticalDividerWidth = 1.0f;
    }
    return _segment;
}
#pragma mark 创建scrollView
- (UIScrollView *)scrollView{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, self.segment.height, self.view.width, self.view.height - self.segment.height)];
        _scrollView.delegate = self;
        _scrollView.pagingEnabled = YES;
        _scrollView.contentSize = CGSizeMake(self.view.width * self.dataArray.count, 0);
    }
    return _scrollView;
}
#pragma mark segment的点击方法
- (void)segmentAction:(HMSegmentedControl *)segment{
    [self.scrollView setContentOffset:CGPointMake(self.view.width * segment.selectedSegmentIndex, 0)];
}

#pragma mark scrollView的滚动方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    NSInteger number = (scrollView.contentOffset.x + self.view.width / self.dataArray.count) / self.view.width;
    
    
    self.segment.selectedSegmentIndex = number;

}
- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRGB:0xfe868f alpha:1];
    UIColor * color = [UIColor whiteColor];
    NSDictionary * dict = [NSDictionary dictionaryWithObject:color forKey:NSForegroundColorAttributeName];
    self.navigationController.navigationBar.titleTextAttributes = dict;
    self.tabBarItem.title = @"精选";
    self.tabBarController.tabBar.hidden = NO;
}


@end
